/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[15]={0,1,8,2,3,4,5,6,7,9,10,11,12};
	do
	{
		if((a[2]+a[3]+a[4]+a[5])
		==(a[8]+a[9]+a[10]+a[11])
		==(a[1]+a[3]+a[6]+a[8])
		==(a[1]+a[4]+a[7]+a[11])
		==(a[5]+a[7]+a[10]+a[12])
		==(a[2]+a[6]+a[9]+a[12]))
		{
			cout<<a[6];
		}
	}while(next_permutation(a+3,a+12));
	return 0;
	
	
}*/


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int a[15] = {0, 1, 8, 2, 12, 4, 5, 6, 7, 9, 10, 11, 3};
    do {
        int sum1 = a[2] + a[3] + a[4] + a[5];
        int sum2 = a[8] + a[9] + a[10] + a[11];
        int sum3 = a[1] + a[3] + a[6] + a[8];
        int sum4 = a[1] + a[4] + a[7] + a[11];
        int sum5 = a[5] + a[7] + a[10] + a[12];
        int sum6 = a[2] + a[6] + a[9] + a[12];
        if (sum1 == sum2 && sum1 == sum3 && sum1 == sum4 && sum1 == sum5 && sum1 == sum6) {
            cout << a[6];
        }
    } while (next_permutation(a + 3, a + 12));
    return 0;
}
	
